import { defineStore } from 'pinia';

interface Message {
  id: number;
  text: string;
  isUser: boolean;
}

export const useChatStore = defineStore('chatStore', {
  state: () => ({
    messages: [] as Message[],
    messageId: 1,
  }),
  actions: {
    addUserMessage(text: string) {
      this.messages.push({
        id: this.messageId++,
        text,
        isUser: true,
      });
    },
    addAiMessage(text: string) {
      this.messages.push({
        id: this.messageId++,
        text,
        isUser: false,
      });
    },
    async fetchAiResponse(userInput: string) {
      const aiResponse = `AI 回应: ${userInput}`;
      this.addAiMessage(aiResponse);
    },
  },
});